/*     */ package com.yc.filters;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import javax.servlet.Filter;
/*     */ import javax.servlet.FilterChain;
/*     */ import javax.servlet.FilterConfig;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.ServletRequest;
/*     */ import javax.servlet.ServletResponse;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ 
/*     */ public class SetCharacterEncodingFilter
/*     */   implements Filter
/*     */ {
/*  68 */   private static final Log log = LogFactory.getLog(SetCharacterEncodingFilter.class);
/*     */ 
/*  76 */   protected String encoding = null;
/*     */ 
/*  83 */   protected FilterConfig filterConfig = null;
/*     */ 
/*  89 */   protected boolean ignore = true;
/*     */ 
/*     */   public void destroy()
/*     */   {
/* 100 */     this.encoding = null;
/* 101 */     this.filterConfig = null;
/*     */   }
/*     */ 
/*     */   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
/*     */     throws IOException, ServletException
/*     */   {
/* 122 */     if ((this.ignore) || (request.getCharacterEncoding() == null)) {
/* 123 */       String encoding = selectEncoding(request);
/* 124 */       if (encoding != null)
/* 125 */         request.setCharacterEncoding(encoding);
/*     */     }
/* 127 */     request.setCharacterEncoding(this.encoding);
/* 128 */     chain.doFilter(request, response);
/*     */   }
/*     */ 
/*     */   public void init(FilterConfig filterConfig)
/*     */     throws ServletException
/*     */   {
/* 139 */     this.filterConfig = filterConfig;
/* 140 */     this.encoding = filterConfig.getInitParameter("encoding");
/* 141 */     String value = filterConfig.getInitParameter("ignore");
/*     */ 
/* 143 */     log.info("encoding = " + this.encoding);
/* 144 */     log.info("value    = " + value);
/*     */ 
/* 146 */     if (value == null)
/* 147 */       this.ignore = true;
/* 148 */     else if (value.equalsIgnoreCase("true"))
/* 149 */       this.ignore = true;
/* 150 */     else if (value.equalsIgnoreCase("yes"))
/* 151 */       this.ignore = true;
/*     */     else
/* 153 */       this.ignore = false;
/*     */   }
/*     */ 
/*     */   protected String selectEncoding(ServletRequest request)
/*     */   {
/* 175 */     return this.encoding;
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.filters.SetCharacterEncodingFilter
 * JD-Core Version:    0.6.2
 */